import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeIndex from '../pages/Home'
import LearnIndex from '../pages/Learn'
import LoginIndex from '../pages/Login'
import NotFoundIndex404 from '../pages/NotFound'
import ShopIndex from '../pages/Shop'

Vue.use(VueRouter)

export default function () {
  const router = new VueRouter({
    routes: [
      {
        path: '/home-index',
        name: 'HomeIndex',
        component: HomeIndex,
        alias: '/'
      },
      {
        path: '/learn-index',
        name: 'LearnIndex',
        component: LearnIndex
      },
      {
        path: '/login-index',
        name: 'LoginIndex',
        component: LoginIndex
      },
      {
        path: '/shop-index',
        name: 'ShopIndex',
        component: ShopIndex
      },
      //捕获所有路由或404路由
      {
        path: "*",
        name: "NotFoundIndex404",
        component: NotFoundIndex404
      }
    ]
  })

  router.beforeEach((to, from, next) => {
    console.log(to)
    next()
  })

  return router;
}
